#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdbool.h>


//nums[] = 1,2,3,4,5,6,7,8,9,10
//k从1~10
bool BinarySearch(int *nums, int numsSize, int k)
{
	//int left = 0;
	//int right = numsSize - 1;
	//int mid = 0;

	//while (left <= right)
	//{
	//	mid = left + (right - left) / 2;
	//	if (k > nums[mid])
	//	{
	//		left = mid + 1;
	//	}
	//	else if (k < nums[mid])
	//	{
	//		right = mid - 1;
	//	}
	//	else
	//	{
	//		return true;
	//	}
	//}
	//return false;


	int left = 0;
	int right = numsSize;
	int mid = 0;

	while (left < right)
	{
		mid = left + (right - left) / 2;
		if (k > nums[mid])
		{
			left = mid + 1;
		}
		else if (k < nums[mid])
		{
			right = mid;
		}
		else
		{
			return true;
		}
	}
	return false;
}

int main()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	int numsSize = sizeof(arr) / sizeof(arr[0]);

	int i = 0;
	for (i = 0; i < 10; i++)
	{
		bool ret = BinarySearch(arr, numsSize, arr[i]);
		if (ret)
		{
			printf("%d\n", arr[i]);
		}
		else
		{
			printf("-1\n");
		}
	}
	return 0;
}